#!/usr/bin/env bash

if [ $# -lt 1 ]; then
	echo "usage: $(basename $0) v0.8.0..master [-l]"
	exit 1
fi

prev_version=$1
linked=$2

githubify() {
	while read name; do
		local url="https://github.com/$name"
		local response_code=$(curl -o /dev/null --silent --head --write-out '%{http_code}\n' $url)

		if [ "200" != "$response_code" ]; then
			echo "$response_code: $url" 1>&2;
		fi

		echo " [$name]($url)"
	done
}

if [ '-l' == "$linked" ]
then
	git log --format="%aN" $prev_version -- | sort -f | uniq | githubify | tr '\n' ','
	echo
else
	git log --format="%aN <%aE>" $prev_version -- | sort -f | uniq
fi
